<?php
/*
 BMForum Datium! Bulletin Board Systems
 Version : Datium!
 
 This is a freeware, but don't change the copyright information.
 A SourceForge Project.
 Web Site: http://www.bmforum.com
 Copyright (C) Bluview Technology
*/
if (!defined('INBMFORUM')) die("Access Denied");
if ($logonutnum == 6) $cancel_guestfile = "reglog";
$add_title = " &gt; $gl[24]";

include("header.php");
navi_bar("$gl[23]", $gl[24], '', 'no');

$authinput = strtoupper($authinput);

if (empty($step)) {
    $echoinfos .= <<<EOT

<form action="misc.php?p=sendpwd" method="post" name="form1" style="margin:0px;">
<br />
$gl[26]<br />
$gl[27]
<input type="text" name="user" size="16" />
$gl[28]  <br />
<br />
<input type="submit" value="$gl[29]" />
<input type="hidden" value="2" name="step" />
EOT;
} elseif ($step == 2) {
    $temp = get_user_info($user);
    if ($temp == 0) {
        $echoinfos .= "<br />$gl[30]";
    } else {
        $useraskinfo = $temp['pwdask'];
        $useranswerinfo = $temp['pwdanswer'];
        $usertype = $temp['ugnum'];
        $usertype = explode("|", $usergroupdata[$usertype]);
        if ($useraskinfo == "") {
            $echoinfos .= "$gl[265] </form>";
            msg_box($gl[24], $echoinfos);
            include("footer.php");
            exit;
        } 
        $authnum = $gd_auth ? getCode(4,1) : rand(10000, 99999);
        $_SESSION[checkauthnum] = $authnum;
        if ($gd_auth == 1) $tmp23s = "<img src='authimg.php?p=1' alt='' />";
            else $tmp23s = "<img src='authimg.php?p=1' alt='' /><img src='authimg.php?p=2' alt='' /><img src='authimg.php?p=3' alt='' /><img src='authimg.php?p=4' alt='' /><img src='authimg.php?p=5' alt='' />";
        if ($usertype[22] != "1" && $usertype[22] != "1") {
            $echoinfos .= <<<EOT
<form action="misc.php?p=sendpwd" method="post" name="form1" style="margin:0px;">

<br />$gl[266] $useraskinfo
<br />$gl[267]<input type="text" name="passanswer" size="16" />
<br />$gl[439]<input type="text" size="25" maxlength="30" name="authinput" />$tmp23s

<input type="submit" value="$gl[29]" >
<input type="hidden" value="3" name="step" /> 
<input type="hidden" name="user" value="$user" />
EOT;
        } else {
            $echoinfos .= "$gl[268]";
        } 
    } 
} elseif ($step == 3) {
    $temp = get_user_info($user);
    $useraskinfo = $temp['pwdask'];
    $useranswerinfo = $temp['pwdanswer'];
    $password = $temp['pwd'];
    $newpassword = rand(100000, 999999);
    $newpwd = md5($newpassword);

    $usertype = $temp['ugnum'];
    $usertype = explode("|", $usergroupdata[$usertype]);
    if (($useraskinfo == "" || $useranswerinfo == md5($useraskinfo) || $_SESSION["checkauthnum"] != $authinput) || ($_SESSION["logintry"] > $maxlogintry-1 && isset($maxlogintry))) {
        $authnum = $gd_auth ? getCode(4,1) : rand(10000, 99999);
        $_SESSION[checkauthnum] = $authnum;
        $echoinfos .= "<ul><li>$gl[265]</li><li>$gl[440]</li></ul> </form>";
        msg_box($gl[24], $echoinfos);
        include("footer.php");
        exit;
    } 
    if ($usertype[22] != "1" && $usertype[21] != "1") {
        if (md5($passanswer) <> $useranswerinfo) {
            $authnum = $gd_auth ? getCode(4,1) : rand(10000, 99999);
            $_SESSION[checkauthnum] = $authnum;
            $_SESSION["logintry"]++;
            $echoinfos .= "<p align=center>$gl[269]</p>";
        } else {
            $nquery = "UPDATE {$database_up}userlist SET pwd='$newpwd' WHERE username='$user'";
            $result = bmbdb_query($nquery);
            $echoinfos .= "<p align='center'>$gl[270]<br /><span class='jiazhongcolor'>" . $newpassword . "</span>";
        } 
    } else {
        $echoinfos .= "$gl[268]";
    } 
} 

$echoinfos .= "</form>";
msg_box($gl[24], $echoinfos);

include("footer.php");
exit;
